﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using APACWP8.Resources;

namespace APACWP8.View
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            this.OrientationChanged += MainPage_OrientationChanged;
            CheckOrientation(LayoutRoot);
        }

        void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            CheckOrientation(LayoutRoot);
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            App.Current.Terminate();
            base.OnBackKeyPress(e);
        }

        private void CheckOrientation(Grid content)
        {
            if (Orientation == PageOrientation.Landscape || Orientation == PageOrientation.LandscapeLeft || Orientation == PageOrientation.LandscapeRight)
                this.FriendsList.Height = 400;
            else
                this.FriendsList.Height = 700;
            if ((Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                content.Margin = new Thickness(0, 0, 0, 0);
            }
            else if ((Orientation & PageOrientation.LandscapeLeft) == (PageOrientation.LandscapeLeft))
            {
                content.Margin = new Thickness(0, 0, 36, 0);
            }
            else if ((Orientation & PageOrientation.LandscapeRight) == (PageOrientation.LandscapeRight))
            {
                content.Margin = new Thickness(36, 0, 0, 0);
            }
        }

        private void Grid_Tapped_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage1.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_4(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage4.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_3(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage3.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_2(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage2.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_5(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage5.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_8(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage8.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_7(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage7.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_6(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage6.xaml", UriKind.Relative));
        }

        private void Grid_Tapped_9(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/PanoramaPage10.xaml", UriKind.Relative));
        }

        private void SettingClick_Click(object sender, EventArgs e)
        {
            App.RootFrame.Navigate(new Uri("/View/SettingPage.xaml", UriKind.Relative));
        }

        private void SearchClick_Click(object sender, EventArgs e)
        {
            App.RootFrame.Navigate(new Uri("/View/SearchPage.xaml", UriKind.Relative));
        }

        private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            App.RootFrame.Navigate(new Uri("/View/PanoramaPage9.xaml", UriKind.Relative));
        }
    }
}